﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CApMFAdminUtils
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPAPPBASELib;
using EMPAPPLICATIONLib;
using EMPAPPSERVICESLib;
using EMPCLIENTCOMMANDSLib;
using EMPMODELLib;
using EMPTYPELIBRARYLib;
using EMPTYPEMGMTLib;
using EMSErrorViewerLib;
using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Utilities;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.ModularFixture;

internal class CApMFAdminUtils
{
  private const string TARGET_LIBRARY_STORAGE_KEY = "TargetConfigurationLibrary";
  internal const string VARIATION_CLASS_NAME = "UnitConfigurationVarPrototype";
  internal const string CONFIGURATION_CLASS_NAME = "UnitConfigurationPrototype";
  internal const string TOOL_PROTOTYPE_CLASS_NAME = "ToolPrototype";
  internal const string TOOL_INSTANCE_CLASS_NAME = "ToolInstance";
  internal const string LAYOUT_CLASS_NAME = "Layout";
  internal const string CONFIGURATION_TYPE_ATTRIBUTE_NAME = "ConfigurationType";
  internal const string CONFIGURATION_TYPE_NAME = "Configuration";
  internal const string UNIT_TYPE_NAME = "Unit";
  internal const string FIXTURE_BASE_TYPE_NAME = "FixtureBase";
  internal const string CONFIGURATION_BITMAP_ATTRIBUTE_NAME = "image";
  internal const string CONFIGURATION_USAGE_ATTRIBUTE_NAME = "Usage";
  internal const string LOCATION_ATTRIBUTE_NAME = "location";
  internal const string ROTATION_ATTRIBUTE_NAME = "rotation";
  internal const string LAYOUT_ATTRIBUTE_NAME = "layout";
  internal const string CHILDREN_ATTRIBUTE = "children";
  internal const string CLASS_DEF_ATTRIBUTE = "Ex_ClassDef";
  internal const string PROTOTYPE_ATTRIBUTE = "prototype";
  internal const string PLACEMENT_ORIGIN_ATTRIBUTE = "PlacementOrigin";
  internal const string BASIC_UNIT_STRUCTURE_ATTRIBUTE_NAME = "BasicUnitStructure";
  internal const string VARIATION_IDS_ATTRIBUTE_NAME = "VariationInternalIds";
  internal const string VARIATION_NAME_ATTRIBUTE_NAME = "VariationName";
  internal const string MIN_TOLERANCE_X_ATTRIBUTE_NAME = "MinToleranceX";
  internal const string MIN_TOLERANCE_Y_ATTRIBUTE_NAME = "MinToleranceY";
  internal const string MIN_TOLERANCE_Z_ATTRIBUTE_NAME = "MinToleranceZ";
  internal const string MAX_TOLERANCE_X_ATTRIBUTE_NAME = "MaxToleranceX";
  internal const string MAX_TOLERANCE_Y_ATTRIBUTE_NAME = "MaxToleranceY";
  internal const string MAX_TOLERANCE_Z_ATTRIBUTE_NAME = "MaxToleranceZ";
  internal const string FIXTURE_UNIT_ORIGIN_ATTRIBUTE_NAME = "FixtureUnitOrigin";
  internal const string INTERMEDIATE_UNIT_PLACEMENT_POINT_ATTRIBUTE_NAME = "IntermediateUnitPlacementPoint";
  internal const string INTERMEDIATE_UNIT_ATTRIBUTE_NAME = "IntermediateUnits";
  internal const string PLACEMENT_POINTS_ATTRIBUTE_NAME = "PlacementPoints";
  internal const string WEIGHT_ATTRIBUTE = "weight";
  internal const string DEFAULT_VARIATION_NAME = "Variation";
  internal const string DEFAULT_VARIATION_OPTION_NAME = "Variation_1";
  private static ITxCommand m_command;
  private static TxCommandPrivateDataStorage m_registryManager;
  private static Image m_compoundResourceImage;
  internal static ResourceManager m_resourceManager;
  internal static int m_targetLibraryId;

  internal static void InitRegistryManager(ITxCommand command)
  {
    CApMFAdminUtils.m_command = command;
    CApMFAdminUtils.m_registryManager = new TxCommandPrivateDataStorage(CApMFAdminUtils.m_command);
  }

  internal static void LoadTargetLibraryFromAppData()
  {
    CApMFAdminUtils.m_targetLibraryId = 0;
    try
    {
      CApMFAdminUtils.m_targetLibraryId = CApMFAdminUtils.m_registryManager.GetIntValue("TargetConfigurationLibrary");
      if (CApMFAdminUtils.DoesTargetLibraryExistInEms())
        return;
      CApMFAdminUtils.m_targetLibraryId = 0;
    }
    catch (Exception ex)
    {
      CApMFAdminUtils.m_targetLibraryId = 0;
    }
  }

  internal static bool DoesTargetLibraryExistInEms()
  {
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    EmpObjectClass empObjectClass = new EmpObjectClass();
    EmpObjectKey[] empObjectKeyArray = new EmpObjectKey[1];
    empObjectKeyArray[0].objectId = CApMFAdminUtils.m_targetLibraryId;
    return empObjectClass.DoObjectsExist(ref empContext, ref empObjectKeyArray)[0];
  }

  internal static void SaveTargetLibraryToAppData(int value)
  {
    new TxCommandPrivateDataStorage(CApMFAdminUtils.m_command).SetIntValue("TargetConfigurationLibrary", value);
    CApMFAdminUtils.m_targetLibraryId = value;
  }

  internal static void DeleteEmsObject(EmpObjectKey objectToDelete)
  {
    CApMFAdminUtils.DeleteEmsObjects(new EmpObjectKey[1]
    {
      objectToDelete
    });
  }

  internal static void DeleteEmsObjects(EmpObjectKey[] objectsToDelete)
  {
    ArrayList outBeAnotherUser = CApMFAdminUtils.GetObjectsThatAreCheckedOutBeAnotherUser(objectsToDelete);
    TxEmsGlobalServicesProvider servicesProvider = new TxEmsGlobalServicesProvider();
    if (outBeAnotherUser.Count > 0)
    {
      CApMFAdminUtils.ShowCheckedOutByAnotherUserErrorMessage((ITxPlanningObject) outBeAnotherUser[0]);
    }
    else
    {
      for (int index = 0; index < objectsToDelete.Length; ++index)
      {
        ITxPlanningObject objectByInternalId = servicesProvider.GetObjectByInternalId(objectsToDelete[index].objectId);
        if ((objectByInternalId.PlatformServicesProvider as TxEmsServicesProvider).CheckInCheckOutState == null)
          CApMFAdminUtils.ExecuteCheckOut(objectsToDelete[index].objectId);
        EmpToolInstanceClass toolInstanceClass = new EmpToolInstanceClass();
        EmpToolPrototypeClass toolPrototypeClass = new EmpToolPrototypeClass();
        EmpContext empContext;
        empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
        EmpObjectKey empObjectKey = !objectByInternalId.IsDerivedFromPlanningType("ToolInstance") ? toolPrototypeClass.GetCollections(ref empContext, ref objectsToDelete[index])[0] : toolInstanceClass[ref empContext, ref objectsToDelete[index]];
        servicesProvider.GetObjectByInternalId(empObjectKey.objectId);
        if ((objectByInternalId.PlatformServicesProvider as TxEmsServicesProvider).CheckInCheckOutState == null)
          CApMFAdminUtils.ExecuteCheckOut(empObjectKey.objectId);
      }
      EmpAppItemList empAppItemList = (EmpAppItemList) new EmpAppItemListClass();
      for (int index = 0; index < objectsToDelete.Length; ++index)
      {
        EmpAppItem empAppItem = (EmpAppItem) new EmpAppItemClass();
        ref ((IEmpAppItem) empAppItem).Key = ref objectsToDelete[index];
        ((IEmpAppItemList) empAppItemList).Add(empAppItem);
      }
      IEmpDeleteCmdParams iempDeleteCmdParams = (IEmpDeleteCmdParams) new EmpDeleteCmdParamsClass();
      iempDeleteCmdParams.Selection = empAppItemList;
      iempDeleteCmdParams.ShowDialog = false;
      ((IEmpCmd) new EmpDeleteCmdClass()).Execute((IEmpCmdParams) iempDeleteCmdParams);
    }
  }

  internal static bool CreateEmsObjects(
    string objectClass,
    int scopeId,
    int numObjects,
    out EmpObjectKey[] newObjectKeys)
  {
    newObjectKeys = (EmpObjectKey[]) null;
    bool emsObjects = CApMFAdminUtils.ConfirmCheckOut(scopeId);
    if (emsObjects)
    {
      try
      {
        EmpNewCmdParamsClass newCmdParamsClass = new EmpNewCmdParamsClass();
        EmpNewCmdClass empNewCmdClass = new EmpNewCmdClass();
        EmpChildrenData[] empChildrenDataArray = new EmpChildrenData[1]
        {
          new EmpChildrenData()
          {
            ChildrenAmount = numObjects,
            ChildrenClass = objectClass
          }
        };
        ref newCmdParamsClass.NewChildren = ref empChildrenDataArray;
        EmpAppItemList empAppItemList = (EmpAppItemList) new EmpAppItemListClass();
        EmpObjectKey empObjectKey = new EmpObjectKey();
        empObjectKey.objectId = scopeId;
        EmpAppItem empAppItem = (EmpAppItem) new EmpAppItemClass();
        ref ((IEmpAppItem) empAppItem).Key = ref empObjectKey;
        ((IEmpAppItemList) empAppItemList).Add(empAppItem);
        newCmdParamsClass.Selection = empAppItemList;
        newCmdParamsClass.ShowDialog = false;
        empNewCmdClass.Execute((IEmpCmdParams) newCmdParamsClass);
        IEmpAppItemList resultItems = (IEmpAppItemList) ((IEmpResultItems) empNewCmdClass.Result).ResultItems;
        newObjectKeys = new EmpObjectKey[resultItems.Size];
        for (int index = 0; index < resultItems.Size; ++index)
        {
          newObjectKeys[index] = ((IEmpAppItem) resultItems.Item(index)).Key;
          if (newObjectKeys[index].objectId == 0)
            emsObjects = false;
        }
      }
      catch (Exception ex)
      {
        new CoEEVErrorViewerLauncherClass().LoadInfoFromXml(ex.Message);
        newObjectKeys = (EmpObjectKey[]) null;
        emsObjects = false;
      }
    }
    return emsObjects;
  }

  internal static bool CreateEmsObject(string objectClass, int scopeId, out IEmpAppItem objectItem)
  {
    EmpObjectKey[] newObjectKeys = (EmpObjectKey[]) null;
    objectItem = (IEmpAppItem) new EmpAppItemClass();
    bool emsObjects = CApMFAdminUtils.CreateEmsObjects(objectClass, scopeId, 1, out newObjectKeys);
    if (emsObjects)
      ref objectItem.Key = ref newObjectKeys[0];
    return emsObjects;
  }

  internal static bool ConnectEmsObject(EmpObjectKey sourceKey, EmpObjectKey targetKey)
  {
    bool flag = CApMFAdminUtils.ConfirmCheckOut(targetKey.objectId);
    if (flag)
    {
      try
      {
        EmpConnectCmdParamsClass connectCmdParamsClass = new EmpConnectCmdParamsClass();
        EmpAppItemList empAppItemList1 = (EmpAppItemList) new EmpAppItemListClass();
        EmpAppItemList empAppItemList2 = (EmpAppItemList) new EmpAppItemListClass();
        EmpConnectCmdClass empConnectCmdClass = new EmpConnectCmdClass();
        EmpAppItem empAppItem1 = (EmpAppItem) new EmpAppItemClass();
        ref ((IEmpAppItem) empAppItem1).Key = ref sourceKey;
        ((IEmpAppItemList) empAppItemList1).Add(empAppItem1);
        connectCmdParamsClass.Selection = empAppItemList1;
        EmpAppItem empAppItem2 = (EmpAppItem) new EmpAppItemClass();
        ref ((IEmpAppItem) empAppItem2).Key = ref targetKey;
        ((IEmpAppItemList) empAppItemList2).Add(empAppItem2);
        connectCmdParamsClass.Targets = empAppItemList2;
        connectCmdParamsClass.ShowDialog = false;
        empConnectCmdClass.Execute((IEmpCmdParams) connectCmdParamsClass);
      }
      catch (Exception ex)
      {
        new CoEEVErrorViewerLauncherClass().LoadInfoFromXml(ex.Message);
        flag = false;
      }
    }
    return flag;
  }

  internal static void SetObjectName(int objectId, string caption)
  {
    EmpFieldValue[] empFieldValueArray = new EmpFieldValue[2];
    empFieldValueArray[0].fieldName = nameof (caption);
    empFieldValueArray[0].FieldValue = (object) caption;
    empFieldValueArray[1].fieldName = "name";
    empFieldValueArray[1].FieldValue = (object) caption;
    EmpNodeFieldsValues[] nodeFieldsValuesArray = new EmpNodeFieldsValues[1]
    {
      new EmpNodeFieldsValues()
      {
        Node = {
          objectId = objectId
        },
        FieldsValues = empFieldValueArray
      }
    };
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    EmpNodesServices empNodesServices = (EmpNodesServices) new EmpNodesServicesClass();
    try
    {
      ((IEmpNodesServices) empNodesServices).SetFields(ref empContext, ref nodeFieldsValuesArray);
    }
    catch (Exception ex)
    {
      new CoEEVErrorViewerLauncherClass().LoadInfoFromXml(ex.Message);
    }
  }

  internal static int GetInstanceId(EmpObjectKey parent, EmpObjectKey key)
  {
    int instanceId = 0;
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    EmpObjectKey[] children = new EmpToolPrototypeClass().GetChildren(ref empContext, ref parent);
    for (int index = 0; index < children.Length; ++index)
    {
      if (new EmpToolInstanceClass()[ref empContext, ref children[index]].objectId == key.objectId)
        instanceId = children[index].objectId;
    }
    return instanceId;
  }

  internal static ITxPlanningObject GetPrototype(ITxPlanningObject obj)
  {
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    IEmpObject iempObject = (IEmpObject) new EmpObjectClass();
    EmpObjectKey empObjectKey = new EmpObjectKey();
    ITxEmsServicesProvider servicesProvider = (ITxEmsServicesProvider) obj.PlatformServicesProvider;
    empObjectKey.objectId = servicesProvider.InternalId;
    EmpFieldInfo field = iempObject.GetField(ref empContext, ref empObjectKey, "prototype");
    int num = (int) field.Value;
    return (TxApplication.ActiveDocument.PlatformGlobalServicesProvider as TxEmsGlobalServicesProvider).GetObjectByInternalId((int) field.Value);
  }

  internal static TxObjectList GetPlanningObjectDescendants(TxPlanningObject planningObject)
  {
    TxObjectList objectDescendants = new TxObjectList();
    EmpObjectKey empObjectKey;
    empObjectKey.objectId = (planningObject.PlatformServicesProvider as TxEmsServicesProvider).InternalId;
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    EmpObjectKey[] children = ((IEmpToolPrototype) new EmpToolPrototypeClass()).GetChildren(ref empContext, ref empObjectKey);
    TxEmsGlobalServicesProvider servicesProvider = TxApplication.ActiveDocument.PlatformGlobalServicesProvider as TxEmsGlobalServicesProvider;
    for (int index = 0; index < children.Length; ++index)
    {
      ITxPlanningObject objectByInternalId = servicesProvider.GetObjectByInternalId(children[index].objectId);
      ((Collection<ITxObject>) objectDescendants).Add((ITxObject) objectByInternalId);
    }
    return objectDescendants;
  }

  internal static void ExecuteCheckOut(int objectId)
  {
    IEmpCmd iempCmd = (IEmpCmd) new EmpCheckOutCmdClass();
    IEmpCheckOutCmdParams checkOutCmdParams = (IEmpCheckOutCmdParams) new EmpCheckOutCmdParamsClass();
    EmpAppItemList empAppItemList = (EmpAppItemList) new EmpAppItemListClass();
    EmpAppItem empAppItem = (EmpAppItem) new EmpAppItemClass();
    EmpObjectKey empObjectKey;
    empObjectKey.objectId = objectId;
    ref ((IEmpAppItem) empAppItem).Key = ref empObjectKey;
    ((IEmpAppItemList) empAppItemList).Add(empAppItem);
    checkOutCmdParams.Selection = empAppItemList;
    checkOutCmdParams.ShowDialog = false;
    checkOutCmdParams.Recursive = false;
    iempCmd.Execute((IEmpCmdParams) checkOutCmdParams);
  }

  internal static bool IsDescendant(int parentId, int childId)
  {
    bool flag = false;
    if (childId > 0)
    {
      EmpContext empContext;
      empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
      EmpToolPrototypeClass toolPrototypeClass = new EmpToolPrototypeClass();
      EmpObjectKey empObjectKey;
      empObjectKey.objectId = parentId;
      foreach (EmpObjectKey child in toolPrototypeClass.GetChildren(ref empContext, ref empObjectKey))
      {
        if (child.objectId == childId)
        {
          flag = true;
          break;
        }
      }
    }
    return flag;
  }

  internal static Image GetCompoundResourceImage()
  {
    if (CApMFAdminUtils.m_compoundResourceImage == null)
    {
      EmpContext empContext;
      empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
      EmpClassDefinition empClassDefinition = (EmpClassDefinition) new EmpClassDefinitionClass();
      ((IEmpClassDefinition) empClassDefinition).GetAllClasses(ref empContext);
      EmpTypeKey[] empTypeKeyArray = new EmpTypeKey[1]
      {
        ((IEmpClassDefinition) empClassDefinition).GetHardClassByName(ref empContext, "CompoundResource")
      };
      EmpIconKey empIconKey = ((IEmpClassDefinition) empClassDefinition)[ref empContext, ref empTypeKeyArray[0]];
      IEmpAppIcons iempAppIcons = (IEmpAppIcons) new EmpAppIconsClass();
      int[] numArray = (int[]) null;
      EmpIconKey[] empIconKeyArray = (EmpIconKey[]) null;
      iempAppIcons.GetClassIcons(ref empIconKeyArray, ref numArray);
      Bitmap bitmap = (Bitmap) null;
      for (int index = 0; index < numArray.Length; ++index)
      {
        IntPtr hicon = new IntPtr((int) numArray.GetValue(index));
        if (((EmpIconKey) empIconKeyArray.GetValue(index)).Equals((object) empIconKey))
        {
          bitmap = Bitmap.FromHicon(hicon);
          break;
        }
      }
      CApMFAdminUtils.m_compoundResourceImage = (Image) bitmap;
    }
    return CApMFAdminUtils.m_compoundResourceImage;
  }

  internal static void RemoveDeletedObjects(int internalId, ArrayList childrenIdsList)
  {
    EmpObjectKey empObjectKey;
    empObjectKey.objectId = internalId;
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    EmpToolPrototype empToolPrototype = (EmpToolPrototype) new EmpToolPrototypeClass();
    EmpObjectKey[] children = ((IEmpToolPrototype) empToolPrototype).GetChildren(ref empContext, ref empObjectKey);
    for (int index1 = 0; index1 < children.Length; ++index1)
    {
      EmpToolInstanceClass toolInstanceClass = new EmpToolInstanceClass();
      EmpObjectKey objectToDelete1 = toolInstanceClass[ref empContext, ref children[index1]];
      bool flag1 = false;
      for (int index2 = 0; index2 < childrenIdsList.Count && !flag1; ++index2)
      {
        if (Convert.ToInt32(childrenIdsList[index2]) == children[index1].objectId)
          flag1 = true;
      }
      if (!flag1)
      {
        CApMFAdminUtils.DeleteEmsObject(children[index1]);
        bool flag2 = true;
        IEmpObject iempObject = (IEmpObject) new EmpObjectClass();
        if (iempObject.IsKindOf(ref empContext, ref objectToDelete1, "UnitConfigurationPrototype"))
        {
          EmpFieldInfo field = iempObject.GetField(ref empContext, ref objectToDelete1, "ConfigurationType");
          if (field.Value != null && ((string) field.Value).Equals("Unit"))
            flag2 = false;
        }
        else if (!iempObject.IsKindOf(ref empContext, ref objectToDelete1, "UnitConfigurationVarPrototype"))
          flag2 = false;
        if (flag2)
        {
          if (iempObject.IsKindOf(ref empContext, ref objectToDelete1, "UnitConfigurationVarPrototype"))
          {
            foreach (EmpObjectKey child in ((IEmpToolPrototype) empToolPrototype).GetChildren(ref empContext, ref objectToDelete1))
            {
              EmpObjectKey objectToDelete2 = toolInstanceClass[ref empContext, ref child];
              CApMFAdminUtils.DeleteEmsObject(child);
              CApMFAdminUtils.DeleteEmsObject(objectToDelete2);
            }
          }
          if (((IEmpToolPrototype) empToolPrototype).GetInstances(ref empContext, ref objectToDelete1).Length == 0)
            CApMFAdminUtils.DeleteEmsObject(objectToDelete1);
        }
      }
    }
  }

  internal static bool ConfirmCheckOut(int internalId)
  {
    bool flag = true;
    ITxPlanningObject objectByInternalId = new TxEmsGlobalServicesProvider().GetObjectByInternalId(internalId);
    TxEmsServicesProvider servicesProvider = objectByInternalId.PlatformServicesProvider as TxEmsServicesProvider;
    if (servicesProvider.CheckInCheckOutState == 2)
    {
      CApMFAdminUtils.ShowCheckedOutByAnotherUserErrorMessage(objectByInternalId);
      flag = false;
    }
    else if (servicesProvider.CheckInCheckOutState == null)
      CApMFAdminUtils.ExecuteCheckOut(internalId);
    return flag;
  }

  internal static void ShowCheckedOutByAnotherUserErrorMessage(ITxPlanningObject planningObj)
  {
    string planningObjectName = TxObjectEx.GetPlanningObjectName((ITxObject) planningObj);
    string str1 = CApMFAdminUtils.m_resourceManager.GetString("CHECK_OUT_ERROR");
    string str2 = CApMFAdminUtils.m_resourceManager.GetString("OBJECT_CHECKED_OUT_BY_ANOTHER_USER_ERROR");
    int num = (int) TxMessageBox.Show($"{str1} {planningObjectName}{str2}", CApMFAdminUtils.m_resourceManager.GetString("CMD_CONFIGURATION_ADMINISTRATOR_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
  }

  internal static void ImportFields(TxObjectList objList, string[] attributes, string category)
  {
    TxEmsCacheManager txEmsCacheManager = new TxEmsCacheManager();
    txEmsCacheManager[category].RootObjects = objList;
    txEmsCacheManager[category].SetAttributes(attributes);
    txEmsCacheManager.CacheData();
  }

  internal static void GetPrototypesWithPlacementPoints(
    TxPlanningObject planningObj,
    ref ArrayList protoList)
  {
    foreach (TxPlanningObject planningObj1 in (Collection<ITxObject>) (planningObj.GetField("children") as TxObjectList))
      CApMFAdminUtils.GetPrototypesWithPlacementPointsInternal(planningObj1, ref protoList);
  }

  private static void GetPrototypesWithPlacementPointsInternal(
    TxPlanningObject planningObj,
    ref ArrayList protoList)
  {
    TxPlanningObject field = planningObj.GetField("prototype") as TxPlanningObject;
    if (field.IsDerivedFromPlanningType("UnitConfigurationPrototype"))
    {
      foreach (TxPlanningObject planningObj1 in (Collection<ITxObject>) (field.GetField("children") as TxObjectList))
        CApMFAdminUtils.GetPrototypesWithPlacementPointsInternal(planningObj1, ref protoList);
    }
    else
    {
      if (!field.IsDerivedFromPlanningType("ToolPrototype") || planningObj.GetField("PlacementOrigin") == null)
        return;
      TxEmsServicesProvider servicesProvider = field.PlatformServicesProvider as TxEmsServicesProvider;
      protoList.Add((object) servicesProvider.InternalId);
    }
  }

  private static ArrayList GetObjectsThatAreCheckedOutBeAnotherUser(EmpObjectKey[] objectsToDelete)
  {
    ArrayList outBeAnotherUser = new ArrayList();
    TxEmsGlobalServicesProvider servicesProvider = new TxEmsGlobalServicesProvider();
    for (int index = 0; index < objectsToDelete.Length && outBeAnotherUser.Count == 0; ++index)
    {
      ITxPlanningObject objectByInternalId1 = servicesProvider.GetObjectByInternalId(objectsToDelete[index].objectId);
      if ((objectByInternalId1.PlatformServicesProvider as TxEmsServicesProvider).CheckInCheckOutState == 2)
        outBeAnotherUser.Add((object) objectByInternalId1);
      EmpToolInstanceClass toolInstanceClass = new EmpToolInstanceClass();
      EmpToolPrototypeClass toolPrototypeClass = new EmpToolPrototypeClass();
      EmpContext empContext;
      empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
      EmpObjectKey empObjectKey = !objectByInternalId1.IsDerivedFromPlanningType("ToolInstance") ? toolPrototypeClass.GetCollections(ref empContext, ref objectsToDelete[index])[0] : toolInstanceClass[ref empContext, ref objectsToDelete[index]];
      ITxPlanningObject objectByInternalId2 = servicesProvider.GetObjectByInternalId(empObjectKey.objectId);
      if ((objectByInternalId1.PlatformServicesProvider as TxEmsServicesProvider).CheckInCheckOutState == 2)
        outBeAnotherUser.Add((object) objectByInternalId2);
    }
    return outBeAnotherUser;
  }
}
